package cn.javass.dp.memento.example1;

public class Originator {

    private String state = "";

    public Memento createMemento() {
        return new MementoImpl(state);
    }

    public void setMemento(Memento memento) {
        MementoImpl mementoImpl = (MementoImpl) memento;
        this.state = mementoImpl.getState();
    }

    /**
     * 真正的备忘录对象，实现备忘录窄接口
     * 实现成私有内部类，不让外部访问
     */
    private static class MementoImpl implements Memento {
        private String state = "";

        public MementoImpl(String state) {
            this.state = state;
        }

        public String getState() {
            return state;
        }
    }
}
